<template>
  <CompOperate
      :field="field"
      :designer="designer"
      :design-state="designState"
      :parent-list="parentList"
      :parent-widget="parentWidget"
      :sub-form-row-id="subFormRowId"
      :sub-form-row-index="subFormRowIndex"
      :sub-form-col-index="subFormColIndex"
      :index-of-parent-list="indexOfParentList"
      :display-style="field['options'].displayStyle"
  >
    <div class="scene-public-scheduling-doctor" :style="getStyle('area')">
      <div class="scheduling-wrap flex-box" :class="`scheduling-wrap-${optionsInfo.viewModal}`">
        <div class="flex-box-left" :style="getStyle('content')">
          {{ optionsInfo.header.content || '\u00a0' }}
        </div>
        <div class="flex-box-right" :class="viewDirectionName">
          <template v-for="(item,index) in doctorSchedulingInfo">
            <div class="group-first" v-if="optionsInfo.rowDirection" :key="index">
              <template v-for="(itemInfo,key) in item">
                <div class="default-info dept-info" v-if="parseInt(itemInfo.type)===1" :key="key"
                     :style="getStyle('dept')">
                  <div class="dept-name" :style="getStyle('deptName')">
                    <ScrollX>{{ itemInfo?.deptName || '\u00a0' }}</ScrollX>
                  </div>
                </div>
                <div class="default-info doctor-info" :key="key" :style="getStyle('doctor')" v-else>
                  <template v-if="itemInfo?.userName">
                    <div class="left-area">
                      <img :src="itemInfo?.workerPicture" alt="医生" v-on:error="handleError">
                    </div>
                    <div class="right-area">
                      <div class="doctor-name right-item" v-if="true">
                        <div class="name" :style="getStyle('doctorName')">{{ itemInfo?.userName || '\u00a0' }}</div>
                        <div class="level" v-if="itemInfo?.workerTitle" :key="widgetKey">
                          <ScrollX>{{ itemInfo?.workerTitle || '\u00a0' }}</ScrollX>
                        </div>
                      </div>
                      <div class="doctor-describe right-item">
                        <div class="container" :key="widgetKey">
                          <div class="header">[擅长]</div>
                          <div class="content">
                            <ScrollY :content="itemInfo?.workerIntro || '\u00a0'" :pageDuration="10"/>
                          </div>
                        </div>
                      </div>
                      <!--排班的界面-->
                      <div class="doctor-scheduling right-item">
                        <div class="scheduling-inside">
                          <div class="header">[坐诊时间]</div>
                          <div class="content" :data-schedulingContentFormat="optionsInfo['schedulingContentFormat']">
                            <template v-if="optionsInfo['schedulingContentFormat']===1">
                              <ScrollX>
                                {{ itemInfo?.scheduleDateWeek || '\u00a0' }}
                              </ScrollX>
                            </template>
                            <template v-if="optionsInfo['schedulingContentFormat']===2">
                              <div class="content-inside-slice">
                                {{ itemInfo?.scheduleDateWeek || '\u00a0' }}
                              </div>
                            </template>
                            <template v-if="optionsInfo['schedulingContentFormat']===3">
                              <div class="content-inside-omit">
                                {{ itemInfo?.scheduleDateWeek || '\u00a0' }}
                              </div>
                            </template>
                          </div>
                        </div>
                      </div>
                    </div>
                  </template>
                </div>
              </template>
            </div>
            <div class="group-first2" v-if="!optionsInfo.rowDirection" :key="index">
              <template v-for="(itemInfo,key) in item">
                <div class="default-info dept-info" v-if="parseInt(itemInfo.type)===1" :key="key">
                  <div class="dept-name" :style="getStyle('deptName')">
                    <ScrollX>{{ itemInfo?.deptName || '\u00a0' }}</ScrollX>
                  </div>
                </div>
                <div class="default-info doctor-info" :key="key" v-else>
                  <template v-if="itemInfo?.userName">
                    <div class="left-area">
                      <img :src="itemInfo?.workerPicture" alt="医生" v-on:error="handleError">
                    </div>
                    <div class="right-area">
                      <div class="doctor-name right-item" v-if="true">
                        <div class="name" :style="getStyle('doctorName')">{{ itemInfo?.userName || '\u00a0' }}</div>
                        <div class="level" v-if="itemInfo?.workerTitle" :key="widgetKey">
                          <ScrollX>{{ itemInfo?.workerTitle || '\u00a0' }}</ScrollX>
                        </div>
                      </div>
                      <div class="doctor-describe right-item">
                        <div class="container" :key="widgetKey">
                          <div class="header">[擅长]</div>
                          <div class="content">
                            <ScrollY :content="itemInfo?.workerIntro || '\u00a0'" :pageDuration="10"/>
                          </div>
                        </div>
                      </div>
                      <!--排班的界面-->
                      <div class="doctor-scheduling right-item">
                        <div class="scheduling-inside">
                          <div class="header">[坐诊时间]</div>
                          <div class="content" :data-schedulingContentFormat="optionsInfo['schedulingContentFormat']">
                            <template v-if="optionsInfo['schedulingContentFormat']===1">
                              <ScrollX>
                                {{ itemInfo?.scheduleDateWeek || '\u00a0' }}
                              </ScrollX>
                            </template>
                            <template v-if="optionsInfo['schedulingContentFormat']===2">
                              <div class="content-inside-slice">
                                {{ itemInfo?.scheduleDateWeek || '\u00a0' }}
                              </div>
                            </template>
                            <template v-if="optionsInfo['schedulingContentFormat']===3">
                              <div class="content-inside-omit">
                                {{ itemInfo?.scheduleDateWeek || '\u00a0' }}
                              </div>
                            </template>
                          </div>
                        </div>
                      </div>
                    </div>
                  </template>
                </div>
              </template>
            </div>
          </template>
        </div>
      </div>
    </div>
  </CompOperate>
</template>

<script>
import {v4 as uuid} from "uuid";
import {pxToVw} from "@/utils/common";
import emitter from "@/utils/designer/emitter";
import SvgIcon from "@c/public/svg-icon/index.vue";
import ScrollX from "@c/public/seamlessScroll/ScrollX.vue";
import ScrollY from "@c/public/seamlessScroll/ScrollY.vue";
import mixin from "@sc/templateDetails/modules/homeMiddle/fieldMixin";
import CompOperate from "@c/public/form-designer/devType/modules/compOperate.vue";

export default {
  name: "scene-public-scheduling-doctor-widget",

  componentName: "FieldWidget", //必须固定为FieldWidget，用于接收父级组件的broadcast事件

  mixins: [emitter, mixin],

  components: {
    ScrollY,
    SvgIcon,
    ScrollX,
    CompOperate,
  },

  props: {
    widget: Object,
    field: Object,
    parentWidget: Object,
    parentList: Array,
    indexOfParentList: Number,
    designer: Object,
    designState: {
      type: Boolean,
      default: false,
    },
    devType: {
      type: Boolean,
      default: false,
    },
    subFormRowIndex: {
      /* 子表单组件行索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormColIndex: {
      /* 子表单组件列索引，从0开始计数 */
      type: Number,
      default: -1,
    },
    subFormRowId: {
      /* 子表单组件行Id，唯一id且不可变 */
      type: String,
      default: "",
    },
    headTitle: {
      type: String,
      default: "",
    },
    visibleTitle: {
      type: Boolean,
    },
  },

  data() {
    return {
      optionsInfo: Array(),
      widgetKey: uuid(),
      header: require("@a/images/design/header.jpeg"),
      header2: require("@/components/assets/images/design/header.jpeg"),
    }
  },

  computed: {
    //生成唯一的字符串
    getOnlyId() {
      return function () {
        return uuid()
      }
    },

    // 模板的行内样式
    getStyle() {
      return function (val) {
        const self = this;
        let info = (self.optionsInfo) || Object();
        let Obj = Object();
        let dept = (info.dept);
        let doctor = (info.list);
        let header = (info?.header);
        switch (val) {
          case "content":
            Reflect.set(Obj, "color", (header?.color));
            Reflect.set(Obj, "fontWeight", (header?.fontWeight));
            Reflect.set(Obj, "background", (header?.background));
            Reflect.set(Obj, "fontSize", pxToVw(header?.fontSize));
            return Obj;
          case "area":
            Reflect.set(Obj, "height", pxToVw(info.areaHeight));
            return Obj;
          case "dept":
            if (!dept['deptName']?.backgroundImageState) {
              Reflect.set(Obj, "background", dept['background']);
            }
            return Obj;
          case "doctor":
            return Obj;
          case "doctorName":
            Reflect.set(Obj, "fontSize", pxToVw(doctor.doctorNameFontSize));
            Reflect.set(Obj, "fontWeight", (doctor.doctorNameFontWeight));
            return Obj;
          case "deptName":
            Reflect.set(Obj, "color", (dept['deptName'].color));
            Reflect.set(Obj, "fontWeight", (dept['deptName'].fontWeight));
            return Obj;
          case "campus":
            Reflect.set(Obj, "color", (dept['campus'].color));
            Reflect.set(Obj, "fontWeight", (dept['campus'].fontWeight));
            return Obj;
        }
      };
    },

    // 视图排列方式样式名称
    viewDirectionName() {
      let {rowDirection} = this.optionsInfo;
      return rowDirection ? 'flex-box-right-column' : 'flex-box-right-row';
    },

    //获取医生信息
    doctorSchedulingInfo() {
      let devType = (this.devType);
      let {patientListRow, patientListCol, rowDirection} = this.optionsInfo;
      let number = rowDirection ? patientListCol : patientListRow;
      let doctorListInfo = this.$store.getters['getSchedulingDoctorInfo2'];
      let list = devType ? doctorListInfo['apiData'] || [] : doctorListInfo['mockData'] || [];
      let addArr = Array();
      let flattenArr = Array();
      if (list?.length >= (patientListRow * patientListCol)) {
        flattenArr = list.slice(0, (patientListRow * patientListCol));
      } else {
        addArr = (new Array((patientListRow * patientListCol) - list.length).fill({}));
        flattenArr = [...list, ...addArr];
      }
      console.log(number)
      // patientListRow
      return this.$lodash.chunk(flattenArr, number) || []
    },

    // 获取排班的logo
    campusSignInfo() {
      return function (params) {
        if (Reflect.has(params, 'campus')) {
          return params?.campus?.hospitalLogo || ''
        } else {
          return ''
        }
      }
    },
  },

  mounted() {
    this.handleOnMounted();
  },

  methods: {
    // 接收父组件传递过来的数据
    async executeMethod(key, data) {
      switch (key) {
        case "publishListInfo":
          this.widgetKey = uuid();
          let publicListInfo = this.$lodash.cloneDeep(data);
          await this.$store.dispatch('setSchedulingDoctorInfo2', publicListInfo)
          break
      }
    },


    handleError(event) {
      event.target.src = '/tpleditor/resource/assets/images/header.png'
    }
  },

  watch: {
    // 获取配置项
    field: {
      handler: function (val) {
        let key = (val.options.config);
        this.widgetKey = uuid();
        this.optionsInfo = (val.options[key]);
      },
      deep: true,
      immediate: true
    }
  },

  destroyed() {
    this.unregisterFromRefList();
  },
};
</script>

<style lang="scss" scoped>
.scene-public-scheduling-doctor {
  background-color: transparent;
  color: #333;
  height: 100%;
  line-height: 100%;
  display: flex;
  justify-content: center;
  flex-direction: column;
  box-sizing: border-box;
  //transform: scale(2) translate(calc(24.6%), calc(24.6%));

  .scheduling-wrap {
    height: calc(100%);
    display: flex;
    flex-direction: row;
    overflow: hidden;
    justify-content: space-between;

    .flex-box-left {
      flex-basis: 170px;
      min-width: calc(170px);
      background: #0059B3;
      writing-mode: vertical-rl; /* 文字从上到下，从右到左排列 */
      font-weight: 500;
      font-size: 70px;
      height: 100%;
      color: #FFFFFF;
      letter-spacing: 30px;
      align-self: center;
      align-items: center;
      justify-content: center;
      box-sizing: border-box;
      margin-right: 2px;
    }

    .flex-box-right {
      flex-basis: calc(100% - 172px);
      min-width: calc(100% - 172px);
      background: white;
      box-sizing: border-box;
      height: calc(100%);
      display: flex;
      flex-direction: column;
      overflow: hidden;

      .group-first {
        display: flex;
        flex-shrink: 0;
        flex-grow: 1;
        flex-basis: 0;
        overflow: hidden;
        margin-top: 10px;
        align-content: flex-start;
        box-sizing: border-box;

        &:first-child {
          margin-top: 0;
        }

        .default-info {
          flex: 1;
          flex-shrink: 0;
          background-color: rgba(229, 234, 239, 1);
          @include background('design/bg6-1×2');
          display: flex;
          overflow: hidden;
          min-width: calc(100% / 4 - 10px);
          max-width: calc(100% / 4 - 10px);
          box-sizing: border-box;
          padding: 10px 14px 10px 14px;
          margin-left: 10px;
        }

        //医生
        .doctor-info {
          .left-area {
            width: 94px;
            height: 100%;
            border-radius: 4px;
            overflow: hidden;
            flex-shrink: 0;
            border: calc(2px / 2) #E8E8E8 solid;

            img {
              width: 100%;
              height: 100%;
              object-fit: cover;
            }
          }

          .right-area {
            display: flex;
            flex-direction: column;
            margin-left: 6px;
            overflow: hidden;
            flex-grow: 1;

            .right-item {
              flex-shrink: 0;
              flex-grow: 1;
            }

            .doctor-name {
              width: 100%;
              display: flex;
              max-height: 40px;
              flex-direction: row;
              align-items: center;
              overflow: hidden;

              .name {
                line-height: initial;
                white-space: nowrap;
                flex-shrink: 0;
                margin-right: 10px;
                @include singleEllipsis(116px);
                box-sizing: border-box;
                color: black;
                font-size: 28px;
                font-weight: bold;
              }

              .level {
                font-size: 12px;
                color: white;
                display: flex;
                align-self: center;
                align-items: center;
                justify-content: center;
                max-width: calc(100% - 116px);
                line-height: 1.42;
                box-sizing: border-box;
                white-space: nowrap;
                background: #0059B3;
                overflow: hidden;
                border-radius: calc(6px / 2);
                padding: calc(2px / 2) calc(12px / 2);
                flex-basis: 0;
                flex-grow: 1;
              }
            }

            .doctor-describe {
              height: 55px;
              overflow: hidden;
              margin-top: 4px;

              .container {
                width: 100%;
                height: 100%;
                line-height: 1.28;
                box-sizing: border-box;
                font-size: 12px;
                color: rgba(51, 51, 51, 0.8);
                text-align: justify;
                display: flex;
                font-weight: 500;
                flex-direction: row;

                .header {
                  min-width: 64px;
                  color: #0059B3;
                }

                .content {
                  height: 100%;
                  font-size: 12px;
                  color: #333333;
                  line-height: 1.34;
                }
              }
            }

            .doctor-scheduling {
              width: 100%;
              margin-top: 6px;
              font-weight: 500;
              align-self: center;
              align-content: center;
              align-items: center;

              .scheduling-inside {
                width: 100%;
                line-height: 1.45;
                font-size: 12px;
                color: #0059B3;
                text-align: left;
                display: flex;
                overflow: hidden;
                flex-direction: row;

                .header {
                  min-width: 64px;
                  flex-shrink: 0;
                }

                .content {
                  height: 100%;
                  flex-shrink: 0;
                  width: calc(100% - 64px);
                  font-size: 12px;
                  margin-top: 2px;
                  line-height: 1.32;
                  overflow: hidden;

                  .content-inside-slice {
                    width: calc(100%);
                    white-space: nowrap;
                    text-overflow: ellipsis;
                  }

                  .content-inside-omit {
                    width: 100%;
                    @include singleEllipsis(100%)
                  }
                }
              }
            }
          }
        }

        //科室
        .dept-info {
          display: flex;
          flex-shrink: 0;
          box-sizing: border-box;
          flex-direction: column;
          overflow: hidden;
          padding: 20px 20px 20px 20px !important;

          .dept-name {
            height: 110px;
            color: #FFFFFF;
            display: flex;
            width: 100%;
            align-self: center;
            align-items: center;
            justify-content: center;
            font-size: 42px;
            padding: 0 20px;
            box-sizing: border-box;
            @include background('design/dept-1×2');
          }

        }

      }

      .group-first2 {
        display: flex;
        flex-direction: column;
        width: calc((100% / 4) - 10px);
        height: 100%;
        flex-grow: 1;
        margin-left: 10px;
        overflow: hidden;

        .default-info {
          background-color: rgba(229, 234, 239, 1);
          @include background('design/bg6-1×2');
          margin-top: 10px;
          flex-grow: 1;
          height: calc(100% / 7 - 10px);
          padding: 10px 14px 14px 16px;
          box-sizing: border-box;

          &:first-child {
            margin-top: 0;
          }
        }

        // 医生
        .doctor-info {
          display: flex;
          flex-direction: row;

          .left-area {
            width: 94px;
            height: 100%;
            border-radius: 4px;
            overflow: hidden;
            flex-shrink: 0;
            border: calc(2px / 2) #dcdee2 solid;

            img {
              width: 100%;
              height: 100%;
              object-fit: cover;
            }
          }

          .right-area {
            display: flex;
            flex-direction: column;
            margin-left: 6px;
            overflow: hidden;
            flex-grow: 1;

            .right-item {
              flex-shrink: 0;
              flex-grow: 1;
            }

            .doctor-name {
              width: 100%;
              display: flex;
              max-height: 40px;
              overflow: hidden;
              flex-direction: row;

              .name {
                line-height: initial;
                white-space: nowrap;
                color: black;
                flex-shrink: 0;
                margin-right: 10px;
                overflow: hidden;
                @include singleEllipsis(116px);
                box-sizing: border-box;
                font-size: 28px;

                font-weight: bold;
              }

              .level {
                font-size: 12px;
                color: white;
                display: flex;
                align-self: center;
                align-items: center;
                justify-content: center;
                max-width: calc(100% - 116px);
                line-height: 1.42;
                box-sizing: border-box;
                white-space: nowrap;
                background: #0059B3;
                overflow: hidden;
                flex-basis: 0;
                flex-grow: 1;
                border-radius: calc(6px / 2);
                padding: calc(2px / 2) calc(12px / 2);
              }
            }

            .doctor-describe {
              height: 50px;
              overflow: hidden;
              margin-top: 4px;

              .container {
                width: 100%;
                height: 100%;
                line-height: 1.28;
                box-sizing: border-box;
                font-size: 12px;
                color: rgba(51, 51, 51, 0.8);
                text-align: justify;
                display: flex;
                font-weight: 500;
                flex-direction: row;

                .header {
                  min-width: 64px;
                  color: #0059B3;
                }

                .content {
                  height: 100%;
                  font-size: 12px;
                  color: #333333;
                  line-height: 1.34;
                }
              }
            }

            .doctor-scheduling {
              width: 100%;
              margin-top: 6px;
              font-weight: 500;
              align-self: center;
              align-content: center;
              align-items: center;

              .scheduling-inside {
                width: 100%;
                line-height: 1.45;
                font-size: 12px;
                color: #0059B3;
                text-align: left;
                display: flex;
                overflow: hidden;
                flex-direction: row;

                .header {
                  min-width: 64px;
                  flex-shrink: 0;
                }

                .content {
                  height: 100%;
                  flex-shrink: 0;
                  width: calc(100% - 64px);
                  font-size: 12px;
                  margin-top: 2px;
                  line-height: 1.32;
                  overflow: hidden;

                  .content-inside-slice {
                    width: calc(100%);
                    white-space: nowrap;
                    text-overflow: ellipsis;
                  }

                  .content-inside-omit {
                    width: 100%;
                    @include singleEllipsis(100%)
                  }
                }
              }
            }
          }
        }

        //科室
        .dept-info {
          display: flex;
          flex-shrink: 0;
          box-sizing: border-box;
          flex-direction: column;
          overflow: hidden;
          padding: 20px 20px 20px 20px !important;

          .dept-name {
            height: 110px;
            color: #FFFFFF;
            display: flex;
            width: 100%;
            align-self: center;
            align-items: center;
            justify-content: center;
            font-size: 42px;
            padding: 0 20px;
            box-sizing: border-box;
            @include background('design/dept-1×2');
          }

        }
      }
    }

    .flex-box-right-row {
      display: flex;
      flex-direction: row;
    }
  }

  // 模式二
  .scheduling-wrap-2 {
    .flex-box-right {
      .group-first, .group-first2 {
        .dept-info {
          background: #43569B;

          .dept-name {
            background: transparent;
          }
        }

        .doctor-info {
          @include background('design/1-20×2');
          border: 1px rgba(0, 0, 0, 0.6) dotted;

          .right-area {
            .doctor-name .level {
              background: #43569B !important;
              color: #FFFFFF !important;
            }

            .doctor-describe .container .header {
              color: #43569B !important;
            }

            .doctor-scheduling .scheduling-inside .header {
              color: #43569B !important;
            }

            .doctor-scheduling .scheduling-inside .content .content-inside-omit {
              color: #43569B !important;
            }
          }
        }
      }
    }
  }
}
</style>